import os
from datetime import datetime


def stamp_to_str(stamp: float):
    return datetime.fromtimestamp(stamp).strftime('%Y-%m-%d %H:%M:%S')


def byte_to_mb(value: int):
    if value > 0:
        return round(value / 1024 / 1024, 2)
    else:
        return 0


def get_file_info(path):
    prefix = 'depository/'
    _info = os.stat(prefix + path)
    return {
        'name': path.split('/')[-1],
        'size': byte_to_mb(_info.st_size),
        'mtime': stamp_to_str(_info.st_mtime),
        'ctime': stamp_to_str(_info.st_ctime),
        'is_dir': os.path.isdir(prefix + path)
    }
